package com.bnq.logc

import com.bnq.logc.config.LogcConfig
import com.bnq.logc.data.CheckUploadResult
import java.io.File

/**
 * 入口类
 */
object Logc {

    private var isInit = false

    fun init(config: LogcConfig){
        if(isInit){
            return
        }
        isInit = true
        LogcManager.init(config)
    }

    fun v(tag:String,log:String){
        log(LogcLevel.VERBOSE, tag, log)
    }

    fun d(tag:String,log:String){
        log(LogcLevel.DEBUG, tag, log)
    }

    fun i(tag:String,log:String){
        log(LogcLevel.INFO, tag, log)
    }

    fun w(tag:String,log:String){
        log(LogcLevel.WARN, tag, log)
    }

    fun e(tag:String,log:String){
        log(LogcLevel.ERROR, tag, log)
    }

    fun event(tag:String,log:String){
        log(LogcLevel.EVENT, tag, log)
    }

    fun record(tag:String,log:String){
       log(LogcLevel.RECORD, tag, log)
    }

    fun sos(tag:String,log:String){
        log(LogcLevel.SOS, tag, log)
    }

    fun send(level: Int,tag:String,log:String,map:Map<String,Any?>?,isUseDefaultParam:Boolean = true){
        LogcManager.send(level, tag, log, map,isUseDefaultParam)
    }

    private fun log(level:Int, tag: String, log: String){
        LogcManager.log(level, tag, log)
    }

    /**
     * 同步当前日志文件
     */
    fun syncCurrentLog(){
        LogcManager.syncCurrentLog()
    }

    /**
     * 同步日志文件
     */
    fun syncLogFileNow(count:Int = 1,callback:((CheckUploadResult)->Unit)? = null){
        LogcManager.syncLogFileNow(count, callback)
    }

    /**
     * 同步日志文件，指定文件名，文件名格式：YYYY-MM-DD.log
     * 警告：请确保文件名格式正确
     */
    fun syncLogFileNow(files:List<File>, callback:((CheckUploadResult)->Unit)? = null){
        LogcManager.syncLogFileNow(files, callback)
    }

    /**
     * 同步上传非日志文件
     */
    fun syncTmpFileNow(files:List<File>, cloudPathNames:List<String>, callback:((CheckUploadResult)->Unit)? = null){
        LogcManager.syncTmpFileNow(files, cloudPathNames, callback)
    }

    /**
     * 上传文件
     */
    fun getTmpUploadFile() = LogcManager.getTmpUploadFile()
}